<template>
  <el-dialog
      :title="!dataForm.id ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
      <el-form-item label="产品id" prop="productId">
        <el-input v-model="dataForm.productId" placeholder="产品id"></el-input>
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="dataForm.productName" placeholder="产品名称"></el-input>
      </el-form-item>
      <el-form-item label="产品型号" prop="model">
        <el-input v-model="dataForm.model" placeholder="产品型号"></el-input>
      </el-form-item>
      <el-form-item label="涵盖机型" prop="coveredModels">
        <el-input v-model="dataForm.coveredModels" placeholder="涵盖机型"></el-input>
      </el-form-item>
      <el-form-item label="生产者名称" prop="manufacturer">
        <el-input v-model="dataForm.manufacturer" placeholder="生产者名称"></el-input>
      </el-form-item>
      <el-form-item label="生产者的注册地址" prop="manufacturerAddress">
        <el-input v-model="dataForm.manufacturerAddress" placeholder="生产者的注册地址"></el-input>
      </el-form-item>
      <el-form-item label="生产者电话" prop="manufacturerPhone">
        <el-input v-model="dataForm.manufacturerPhone" placeholder="生产者电话"></el-input>
      </el-form-item>
      <el-form-item label="生产者传真" prop="manufacturerFax">
        <el-input v-model="dataForm.manufacturerFax" placeholder="生产者传真"></el-input>
      </el-form-item>
      <el-form-item label="生产者联系人" prop="manufacturerContact">
        <el-input v-model="dataForm.manufacturerContact" placeholder="生产者联系人"></el-input>
      </el-form-item>
      <el-form-item label="生产者邮政编码" prop="manufacturerZipcode">
        <el-input v-model="dataForm.manufacturerZipcode" placeholder="生产者邮政编码"></el-input>
      </el-form-item>
      <el-form-item label="生产厂名称" prop="factory">
        <el-input v-model="dataForm.factory" placeholder="生产厂名称"></el-input>
      </el-form-item>
      <el-form-item label="生产厂的注册地址" prop="factoryAddress">
        <el-input v-model="dataForm.factoryAddress" placeholder="生产厂的注册地址"></el-input>
      </el-form-item>
      <el-form-item label="生产厂电话" prop="factoryPhone">
        <el-input v-model="dataForm.factoryPhone" placeholder="生产厂电话"></el-input>
      </el-form-item>
      <el-form-item label="生产厂传真" prop="factoryFax">
        <el-input v-model="dataForm.factoryFax" placeholder="生产厂传真"></el-input>
      </el-form-item>
      <el-form-item label="生产厂联系人" prop="factoryContact">
        <el-input v-model="dataForm.factoryContact" placeholder="生产厂联系人"></el-input>
      </el-form-item>
      <el-form-item label="生产厂邮政编码" prop="factoryZipcode">
        <el-input v-model="dataForm.factoryZipcode" placeholder="生产厂邮政编码"></el-input>
      </el-form-item>
      <el-form-item label="鉴定依据的标准" prop="judgmentBasis">
        <el-input v-model="dataForm.judgmentBasis" placeholder="鉴定依据的标准"></el-input>
      </el-form-item>
      <el-form-item label="鉴定结论" prop="judgmentConclusion">
        <el-input v-model="dataForm.judgmentConclusion" placeholder="鉴定结论"></el-input>
      </el-form-item>
      <el-form-item label="鉴定报告的签发日期" prop="issueDate">
        <el-input v-model="dataForm.issueDate" placeholder="鉴定报告的签发日期"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
      <el-form-item label="报告状态" prop="reprotStatus">
        <el-input v-model="dataForm.reprotStatus" placeholder="报告状态"></el-input>
      </el-form-item>
      <el-form-item label="批准人" prop="approver">
        <el-input v-model="dataForm.approver" placeholder="批准人"></el-input>
      </el-form-item>
      <el-form-item label="批准人意见" prop="approvalOpinion">
        <el-input v-model="dataForm.approvalOpinion" placeholder="批准人意见"></el-input>
      </el-form-item>
      <el-form-item label="审核人" prop="auditor">
        <el-input v-model="dataForm.auditor" placeholder="审核人"></el-input>
      </el-form-item>
      <el-form-item label="审核人意见" prop="auditOpinion">
        <el-input v-model="dataForm.auditOpinion" placeholder="审核人意见"></el-input>
      </el-form-item>
      <el-form-item label="审核日期" prop="dateOfApproval">
        <el-input v-model="dataForm.dateOfApproval" placeholder="审核日期"></el-input>
      </el-form-item>
      <el-form-item label="项目负责人" prop="projectLeader">
        <el-input v-model="dataForm.projectLeader" placeholder="项目负责人"></el-input>
      </el-form-item>
      <el-form-item label="项目负责人意见" prop="projectLeaderOpinion">
        <el-input v-model="dataForm.projectLeaderOpinion" placeholder="项目负责人意见"></el-input>
      </el-form-item>
      <el-form-item label="项目负责人填写日期" prop="projectLeaderDate">
        <el-input v-model="dataForm.projectLeaderDate" placeholder="项目负责人填写日期"></el-input>
      </el-form-item>
      <el-form-item label="样品图片(产品名称)" prop="pictureProductName">
        <el-input v-model="dataForm.pictureProductName" placeholder="样品图片(产品名称)"></el-input>
      </el-form-item>
      <el-form-item label="样品图片(产品型号)" prop="pictureModel">
        <el-input v-model="dataForm.pictureModel" placeholder="样品图片(产品型号)"></el-input>
      </el-form-item>
      <el-form-item label="备注信息" prop="remarks">
        <el-input v-model="dataForm.remarks" placeholder="备注信息"></el-input>
      </el-form-item>
      <el-form-item label="报告编写人" prop="reportWriter">
        <el-input v-model="dataForm.reportWriter" placeholder="报告编写人"></el-input>
      </el-form-item>
      <el-form-item label="报告编写日期" prop="reportDate">
        <el-input v-model="dataForm.reportDate" placeholder="报告编写日期"></el-input>
      </el-form-item>
      <el-form-item label="报告校核人" prop="reportChecker">
        <el-input v-model="dataForm.reportChecker" placeholder="报告校核人"></el-input>
      </el-form-item>
      <el-form-item label="报告校核意见" prop="reportCheckerOpinion">
        <el-input v-model="dataForm.reportCheckerOpinion" placeholder="报告校核意见"></el-input>
      </el-form-item>
      <el-form-item label="报告校核日期" prop="reportCheckerDate">
        <el-input v-model="dataForm.reportCheckerDate" placeholder="报告校核日期"></el-input>
      </el-form-item>
      <el-form-item label="产品文件路径" prop="productFilePath">
        <el-input v-model="dataForm.productFilePath" placeholder="产品文件路径"></el-input>
      </el-form-item>
      <el-form-item label="pdf路径" prop="pdfPath">
        <el-input v-model="dataForm.pdfPath" placeholder="pdf路径"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        productId: '',
        productName: '',
        model: '',
        coveredModels: '',
        manufacturer: '',
        manufacturerAddress: '',
        manufacturerPhone: '',
        manufacturerFax: '',
        manufacturerContact: '',
        manufacturerZipcode: '',
        factory: '',
        factoryAddress: '',
        factoryPhone: '',
        factoryFax: '',
        factoryContact: '',
        factoryZipcode: '',
        judgmentBasis: '',
        judgmentConclusion: '',
        issueDate: '',
        remark: '',
        reprotStatus: '',
        approver: '',
        approvalOpinion: '',
        auditor: '',
        auditOpinion: '',
        dateOfApproval: '',
        projectLeader: '',
        projectLeaderOpinion: '',
        projectLeaderDate: '',
        pictureProductName: '',
        pictureModel: '',
        remarks: '',
        reportWriter: '',
        reportDate: '',
        reportChecker: '',
        reportCheckerOpinion: '',
        reportCheckerDate: '',
        productFilePath: '',
        pdfPath: ''
      },
      dataRule: {
        productId: [
          {required: true, message: '产品id不能为空', trigger: 'blur'}
        ],
        productName: [
          {required: true, message: '产品名称不能为空', trigger: 'blur'}
        ],
        model: [
          {required: true, message: '产品型号不能为空', trigger: 'blur'}
        ],
        coveredModels: [
          {required: true, message: '涵盖机型不能为空', trigger: 'blur'}
        ],
        manufacturer: [
          {required: true, message: '生产者名称不能为空', trigger: 'blur'}
        ],
        manufacturerAddress: [
          {required: true, message: '生产者的注册地址不能为空', trigger: 'blur'}
        ],
        manufacturerPhone: [
          {required: true, message: '生产者电话不能为空', trigger: 'blur'}
        ],
        manufacturerFax: [
          {required: true, message: '生产者传真不能为空', trigger: 'blur'}
        ],
        manufacturerContact: [
          {required: true, message: '生产者联系人不能为空', trigger: 'blur'}
        ],
        manufacturerZipcode: [
          {required: true, message: '生产者邮政编码不能为空', trigger: 'blur'}
        ],
        factory: [
          {required: true, message: '生产厂名称不能为空', trigger: 'blur'}
        ],
        factoryAddress: [
          {required: true, message: '生产厂的注册地址不能为空', trigger: 'blur'}
        ],
        factoryPhone: [
          {required: true, message: '生产厂电话不能为空', trigger: 'blur'}
        ],
        factoryFax: [
          {required: true, message: '生产厂传真不能为空', trigger: 'blur'}
        ],
        factoryContact: [
          {required: true, message: '生产厂联系人不能为空', trigger: 'blur'}
        ],
        factoryZipcode: [
          {required: true, message: '生产厂邮政编码不能为空', trigger: 'blur'}
        ],
        judgmentBasis: [
          {required: true, message: '鉴定依据的标准不能为空', trigger: 'blur'}
        ],
        judgmentConclusion: [
          {required: true, message: '鉴定结论不能为空', trigger: 'blur'}
        ],
        issueDate: [
          {required: true, message: '鉴定报告的签发日期不能为空', trigger: 'blur'}
        ],
        remark: [
          {required: true, message: '备注不能为空', trigger: 'blur'}
        ],
        reprotStatus: [
          {required: true, message: '报告状态不能为空', trigger: 'blur'}
        ],
        approver: [
          {required: true, message: '批准人不能为空', trigger: 'blur'}
        ],
        approvalOpinion: [
          {required: true, message: '批准人意见不能为空', trigger: 'blur'}
        ],
        auditor: [
          {required: true, message: '审核人不能为空', trigger: 'blur'}
        ],
        auditOpinion: [
          {required: true, message: '审核人意见不能为空', trigger: 'blur'}
        ],
        dateOfApproval: [
          {required: true, message: '审核日期不能为空', trigger: 'blur'}
        ],
        projectLeader: [
          {required: true, message: '项目负责人不能为空', trigger: 'blur'}
        ],
        projectLeaderOpinion: [
          {required: true, message: '项目负责人意见不能为空', trigger: 'blur'}
        ],
        projectLeaderDate: [
          {required: true, message: '项目负责人填写日期不能为空', trigger: 'blur'}
        ],
        pictureProductName: [
          {required: true, message: '样品图片(产品名称)不能为空', trigger: 'blur'}
        ],
        pictureModel: [
          {required: true, message: '样品图片(产品型号)不能为空', trigger: 'blur'}
        ],
        remarks: [
          {required: true, message: '备注信息不能为空', trigger: 'blur'}
        ],
        reportWriter: [
          {required: true, message: '报告编写人不能为空', trigger: 'blur'}
        ],
        reportDate: [
          {required: true, message: '报告编写日期不能为空', trigger: 'blur'}
        ],
        reportChecker: [
          {required: true, message: '报告校核人不能为空', trigger: 'blur'}
        ],
        reportCheckerOpinion: [
          {required: true, message: '报告校核意见不能为空', trigger: 'blur'}
        ],
        reportCheckerDate: [
          {required: true, message: '报告校核日期不能为空', trigger: 'blur'}
        ],
        productFilePath: [
          {required: true, message: '产品文件路径不能为空', trigger: 'blur'}
        ],
        pdfPath: [
          {required: true, message: 'pdf路径不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/reportApproval/productinfo/info/${this.dataForm.id}`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.productId = data.productInfo.productId
              this.dataForm.productName = data.productInfo.productName
              this.dataForm.model = data.productInfo.model
              this.dataForm.coveredModels = data.productInfo.coveredModels
              this.dataForm.manufacturer = data.productInfo.manufacturer
              this.dataForm.manufacturerAddress = data.productInfo.manufacturerAddress
              this.dataForm.manufacturerPhone = data.productInfo.manufacturerPhone
              this.dataForm.manufacturerFax = data.productInfo.manufacturerFax
              this.dataForm.manufacturerContact = data.productInfo.manufacturerContact
              this.dataForm.manufacturerZipcode = data.productInfo.manufacturerZipcode
              this.dataForm.factory = data.productInfo.factory
              this.dataForm.factoryAddress = data.productInfo.factoryAddress
              this.dataForm.factoryPhone = data.productInfo.factoryPhone
              this.dataForm.factoryFax = data.productInfo.factoryFax
              this.dataForm.factoryContact = data.productInfo.factoryContact
              this.dataForm.factoryZipcode = data.productInfo.factoryZipcode
              this.dataForm.judgmentBasis = data.productInfo.judgmentBasis
              this.dataForm.judgmentConclusion = data.productInfo.judgmentConclusion
              this.dataForm.issueDate = data.productInfo.issueDate
              this.dataForm.remark = data.productInfo.remark
              this.dataForm.reprotStatus = data.productInfo.reprotStatus
              this.dataForm.approver = data.productInfo.approver
              this.dataForm.approvalOpinion = data.productInfo.approvalOpinion
              this.dataForm.auditor = data.productInfo.auditor
              this.dataForm.auditOpinion = data.productInfo.auditOpinion
              this.dataForm.dateOfApproval = data.productInfo.dateOfApproval
              this.dataForm.projectLeader = data.productInfo.projectLeader
              this.dataForm.projectLeaderOpinion = data.productInfo.projectLeaderOpinion
              this.dataForm.projectLeaderDate = data.productInfo.projectLeaderDate
              this.dataForm.pictureProductName = data.productInfo.pictureProductName
              this.dataForm.pictureModel = data.productInfo.pictureModel
              this.dataForm.remarks = data.productInfo.remarks
              this.dataForm.reportWriter = data.productInfo.reportWriter
              this.dataForm.reportDate = data.productInfo.reportDate
              this.dataForm.reportChecker = data.productInfo.reportChecker
              this.dataForm.reportCheckerOpinion = data.productInfo.reportCheckerOpinion
              this.dataForm.reportCheckerDate = data.productInfo.reportCheckerDate
              this.dataForm.productFilePath = data.productInfo.productFilePath
              this.dataForm.pdfPath = data.productInfo.pdfPath
            }
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/reportApproval/productinfo/${!this.dataForm.id ? 'save' : 'update'}`),
            method: 'post',
            data: this.$http.adornData({
              'id': this.dataForm.id || undefined,
              'productId': this.dataForm.productId,
              'productName': this.dataForm.productName,
              'model': this.dataForm.model,
              'coveredModels': this.dataForm.coveredModels,
              'manufacturer': this.dataForm.manufacturer,
              'manufacturerAddress': this.dataForm.manufacturerAddress,
              'manufacturerPhone': this.dataForm.manufacturerPhone,
              'manufacturerFax': this.dataForm.manufacturerFax,
              'manufacturerContact': this.dataForm.manufacturerContact,
              'manufacturerZipcode': this.dataForm.manufacturerZipcode,
              'factory': this.dataForm.factory,
              'factoryAddress': this.dataForm.factoryAddress,
              'factoryPhone': this.dataForm.factoryPhone,
              'factoryFax': this.dataForm.factoryFax,
              'factoryContact': this.dataForm.factoryContact,
              'factoryZipcode': this.dataForm.factoryZipcode,
              'judgmentBasis': this.dataForm.judgmentBasis,
              'judgmentConclusion': this.dataForm.judgmentConclusion,
              'issueDate': this.dataForm.issueDate,
              'remark': this.dataForm.remark,
              'reprotStatus': this.dataForm.reprotStatus,
              'approver': this.dataForm.approver,
              'approvalOpinion': this.dataForm.approvalOpinion,
              'auditor': this.dataForm.auditor,
              'auditOpinion': this.dataForm.auditOpinion,
              'dateOfApproval': this.dataForm.dateOfApproval,
              'projectLeader': this.dataForm.projectLeader,
              'projectLeaderOpinion': this.dataForm.projectLeaderOpinion,
              'projectLeaderDate': this.dataForm.projectLeaderDate,
              'pictureProductName': this.dataForm.pictureProductName,
              'pictureModel': this.dataForm.pictureModel,
              'remarks': this.dataForm.remarks,
              'reportWriter': this.dataForm.reportWriter,
              'reportDate': this.dataForm.reportDate,
              'reportChecker': this.dataForm.reportChecker,
              'reportCheckerOpinion': this.dataForm.reportCheckerOpinion,
              'reportCheckerDate': this.dataForm.reportCheckerDate,
              'productFilePath': this.dataForm.productFilePath,
              'pdfPath': this.dataForm.pdfPath
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>
